﻿(function () {
    "use strict";

    /*DEBUG VARS*/
    var DEBUG = false;

    function log(str) {
        
        if (DEBUG && console && console.log) {
            console.log(str);
        }
    }


    function stripScripts(s) {
        var div = document.createElement('div');
        div.innerHTML = s;
        var scripts = div.getElementsByTagName('script');
        var i = scripts.length;
        while (i--) {
            scripts[i].parentNode.removeChild(scripts[i]);
        }
        return div.innerHTML;
    }


    function htmlSpecialChars(str) {

        var specialList = [
            ["Á" , "&Aacute;"],
            ["á" , "&aacute;"],
            ["Â" , "&Acirc;"],
            ["â" , "&acirc;"],
            ["´" , "&acute;"],
            ["Æ" , "&AElig;"],
            ["æ" , "&aelig;"],
            ["À" , "&Agrave;"],
            ["à" , "&agrave;"],
            ["ℵ" , "&alefsym;"],
            ["Α" , "&Alpha;"],
            ["α" , "&alpha;"],
            ["&" , "&amp;"],
            ["∧" , "&and;"],
            ["∠" , "&ang;"],
            ["'" , "&apos;"],
            ["Å" , "&Aring;"],
            ["å" , "&aring;"],
            ["≈" , "&asymp;"],
            ["Ã" , "&Atilde;"],
            ["ã" , "&atilde;"],
            ["Ä" , "&Auml;"],
            ["ä" , "&auml;"],
            ["„" , "&bdquo;"],
            ["Β" , "&Beta;"],
            ["β" , "&beta;"],
            ["¦" , "&brvbar;"],
            ["•" , "&bull;"],
            ["∩" , "&cap;"],
            ["Ç" , "&Ccedil;"],
            ["ç" , "&ccedil;"],
            ["¸" , "&cedil;"],
            ["¢" , "&cent;"],
            ["Χ" , "&Chi;"],
            ["χ" , "&chi;"],
            ["ˆ" , "&circ;"],
            ["♣" , "&clubs;"],
            ["≅" , "&cong;"],
            ["©" , "&copy;"],
            ["↵" , "&crarr;"],
            ["∪" , "&cup;"],
            ["¤" , "&curren;"],
            ["†" , "&dagger;"],
            ["‡" , "&Dagger;"],
            ["↓" , "&darr;"],
            ["⇓" , "&dArr;"],
            ["°" , "&deg;"],
            ["Δ" , "&Delta;"],
            ["δ" , "&delta;"],
            ["♦" , "&diams;"],
            ["÷" , "&divide;"],
            ["É" , "&Eacute;"],
            ["é" , "&eacute;"],
            ["Ê" , "&Ecirc;"],
            ["ê" , "&ecirc;"],
            ["È" , "&Egrave;"],
            ["è" , "&egrave;"],
            ["∅" , "&empty;"],
            [" " , "&emsp;"],
            [" " , "&ensp;"],
            ["Ε" , "&Epsilon;"],
            ["ε" , "&epsilon;"],
            ["≡" , "&equiv;"],
            ["Η" , "&Eta;"],
            ["η" , "&eta;"],
            ["Ð" , "&ETH;"],
            ["ð" , "&eth;"],
            ["Ë" , "&Euml;"],
            ["ë" , "&euml;"],
            ["€" , "&euro;"],
            ["∃" , "&exist;"],
            ["ƒ" , "&fnof;"],
            ["∀" , "&forall;"],
            ["½" , "&frac12;"],
            ["¼" , "&frac14;"],
            ["¾" , "&frac34;"],
            ["⁄" , "&frasl;"],
            ["Γ" , "&Gamma;"],
            ["γ" , "&gamma;"],
            ["≥" , "&ge;"],
            [">" , "&gt;"],
            ["↔" , "&harr;"],
            ["⇔" , "&hArr;"],
            ["♥" , "&hearts;"],
            ["…" , "&hellip;"],
            ["Í" , "&Iacute;"],
            ["í" , "&iacute;"],
            ["Î" , "&Icirc;"],
            ["î" , "&icirc;"],
            ["¡" , "&iexcl;"],
            ["Ì" , "&Igrave;"],
            ["ì" , "&igrave;"],
            ["ℑ" , "&image;"],
            ["∞" , "&infin;"],
            ["∫" , "&int;"],
            ["Ι" , "&Iota;"],
            ["ι" , "&iota;"],
            ["¿" , "&iquest;"],
            ["∈" , "&isin;"],
            ["Ï" , "&Iuml;"],
            ["ï" , "&iuml;"],
            ["Κ" , "&Kappa;"],
            ["κ" , "&kappa;"],
            ["Λ" , "&Lambda;"],
            ["λ" , "&lambda;"],
            ["〈" , "&lang;"],
            ["«" , "&laquo;"],
            ["←" , "&larr;"],
            ["⇐" , "&lArr;"],
            ["⌈" , "&lceil;"],
            ["“" , "&ldquo;"],
            ["≤" , "&le;"],
            ["⌊" , "&lfloor;"],
            ["∗" , "&lowast;"],
            ["◊" , "&loz;"],
            ["‹" , "&lsaquo;"],
            ["‘" , "&lsquo;"],
            ["<" , "&lt;"],
            ["¯" , "&macr;"],
            ["—" , "&mdash;"],
            ["µ" , "&micro;"],
            ["·" , "&middot;"],
            ["−" , "&minus;"],
            ["Μ" , "&Mu;"],
            ["μ" , "&mu;"],
            ["∇" , "&nabla;"],
            ["" , "&nbsp;"],
            ["–" , "&ndash;"],
            ["≠" , "&ne;"],
            ["∋" , "&ni;"],
            ["¬" , "&not;"],
            ["∉" , "&notin;"],
            ["⊄" , "&nsub;"],
            ["Ñ" , "&Ntilde;"],
            ["ñ" , "&ntilde;"],
            ["Ν" , "&Nu;"],
            ["ν" , "&nu;"],
            ["Ó" , "&Oacute;"],
            ["ó" , "&oacute;"],
            ["Ô" , "&Ocirc;"],
            ["ô" , "&ocirc;"],
            ["Œ" , "&OElig;"],
            ["œ" , "&oelig;"],
            ["Ò" , "&Ograve;"],
            ["ò" , "&ograve;"],
            ["‾" , "&oline;"],
            ["Ω" , "&Omega;"],
            ["ω" , "&omega;"],
            ["Ο" , "&Omicron;"],
            ["ο" , "&omicron;"],
            ["⊕" , "&oplus;"],
            ["∨" , "&or;"],
            ["ª" , "&ordf;"],
            ["º" , "&ordm;"],
            ["Ø" , "&Oslash;"],
            ["ø" , "&oslash;"],
            ["Õ" , "&Otilde;"],
            ["õ" , "&otilde;"],
            ["⊗" , "&otimes;"],
            ["Ö" , "&Ouml;"],
            ["ö" , "&ouml;"],
            ["¶" , "&para;"],
            ["∂" , "&part;"],
            ["‰" , "&permil;"],
            ["⊥" , "&perp;"],
            ["Φ" , "&Phi;"],
            ["φ" , "&phi;"],
            ["Π" , "&Pi;"],
            ["π" , "&pi;"],
            ["ϖ" , "&piv;"],
            ["±" , "&plusmn;"],
            ["£" , "&pound;"],
            ["′" , "&prime;"],
            ["″" , "&Prime;"],
            ["∏" , "&prod;"],
            ["∝" , "&prop;"],
            ["Ψ" , "&Psi;"],
            ["ψ" , "&psi;"],
            ["\"" , "&quot;"],
            ["√" , "&radic;"],
            ["〉" , "&rang;"],
            ["»" , "&raquo;"],
            ["→" , "&rarr;"],
            ["⇒" , "&rArr;"],
            ["⌉" , "&rceil;"],
            ["”" , "&rdquo;"],
            ["ℜ" , "&real;"],
            ["®" , "&reg;"],
            ["⌋" , "&rfloor;"],
            ["Ρ" , "&Rho;"],
            ["ρ" , "&rho;"],
            ["›" , "&rsaquo;"],
            ["’" , "&rsquo;"],
            ["‚" , "&sbquo;"],
            ["Š" , "&Scaron;"],
            ["š" , "&scaron;"],
            ["⋅" , "&sdot;"],
            ["§" , "&sect;"],
            ["Σ" , "&Sigma;"],
            ["σ" , "&sigma;"],
            ["ς" , "&sigmaf;"],
            ["∼" , "&sim;"],
            ["♠" , "&spades;"],
            ["⊂" , "&sub;"],
            ["⊆" , "&sube;"],
            ["∑" , "&sum;"],
            ["⊃" , "&sup;"],
            ["¹" , "&sup1;"],
            ["²" , "&sup2;"],
            ["³" , "&sup3;"],
            ["⊇" , "&supe;"],
            ["ß" , "&szlig;"],
            ["Τ" , "&Tau;"],
            ["τ" , "&tau;"],
            ["∴" , "&there4;"],
            ["Θ" , "&Theta;"],
            ["θ" , "&theta;"],
            ["ϑ" , "&thetasym;"],
            [" " , "&thinsp;"],
            ["Þ" , "&THORN;"],
            ["þ" , "&thorn;"],
            ["˜" , "&tilde;"],
            ["×" , "&times;"],
            ["™" , "&trade;"],
            ["Ú" , "&Uacute;"],
            ["ú" , "&uacute;"],
            ["↑" , "&uarr;"],
            ["⇑" , "&uArr;"],
            ["Û" , "&Ucirc;"],
            ["û" , "&ucirc;"],
            ["Ù" , "&Ugrave;"],
            ["ù" , "&ugrave;"],
            ["¨" , "&uml;"],
            ["ϒ" , "&upsih;"],
            ["Υ" , "&Upsilon;"],
            ["υ" , "&upsilon;"],
            ["Ü" , "&Uuml;"],
            ["ü" , "&uuml;"],
            ["℘" , "&weierp;"],
            ["Ξ" , "&Xi;"],
            ["ξ" , "&xi;"],
            ["Ý" , "&Yacute;"],
            ["ý" , "&yacute;"],
            ["¥" , "&yen;"],
            ["ÿ" , "&yuml;"],
            ["Ÿ" , "&Yuml;"],
            ["Ζ" , "&Zeta;"],
            ["ζ" , "&zeta;"],
            ["Á" , "&#193;"],
            ["á" , "&#225;"],
            ["Â" , "&#194;"],
            ["â" , "&#226;"],
            ["´" , "&#180;"],
            ["Æ" , "&#198;"],
            ["æ" , "&#230;"],
            ["À" , "&#192;"],
            ["à" , "&#224;"],
            ["ℵ" , "&#8501;"],
            ["Α" , "&#913;"],
            ["α" , "&#945;"],
            ["&" , "&#38;"],
            ["&" , "&#038;"],
            ["∧" , "&#8743;"],
            ["∠" , "&#8736;"],
            ["'" , "&#39;"],
            ["'" , "&#039;"],
            ["Å" , "&#197;"],
            ["å" , "&#229;"],
            ["≈" , "&#8776;"],
            ["Ã" , "&#195;"],
            ["ã" , "&#227;"],
            ["Ä" , "&#196;"],
            ["ä" , "&#228;"],
            ["„" , "&#8222;"],
            ["Β" , "&#914;"],
            ["β" , "&#946;"],
            ["¦" , "&#166;"],
            ["•" , "&#8226;"],
            ["∩" , "&#8745;"],
            ["Ç" , "&#199;"],
            ["ç" , "&#231;"],
            ["¸" , "&#184;"],
            ["¢" , "&#162;"],
            ["Χ" , "&#935;"],
            ["χ" , "&#967;"],
            ["ˆ" , "&#710;"],
            ["♣" , "&#9827;"],
            ["≅" , "&#8773;"],
            ["©" , "&#169;"],
            ["↵" , "&#8629;"],
            ["∪" , "&#8746;"],
            ["¤" , "&#164;"],
            ["†" , "&#8224;"],
            ["‡" , "&#8225;"],
            ["↓" , "&#8595;"],
            ["⇓" , "&#8659;"],
            ["°" , "&#176;"],
            ["Δ" , "&#916;"],
            ["δ" , "&#948;"],
            ["♦" , "&#9830;"],
            ["÷" , "&#247;"],
            ["É" , "&#201;"],
            ["é" , "&#233;"],
            ["Ê" , "&#202;"],
            ["ê" , "&#234;"],
            ["È" , "&#200;"],
            ["è" , "&#232;"],
            ["∅" , "&#8709;"],
            [" " , "&#8195;"],
            [" " , "&#8194;"],
            ["Ε" , "&#917;"],
            ["ε" , "&#949;"],
            ["≡" , "&#8801;"],
            ["Η" , "&#919;"],
            ["η" , "&#951;"],
            ["Ð" , "&#208;"],
            ["ð" , "&#240;"],
            ["Ë" , "&#203;"],
            ["ë" , "&#235;"],
            ["€" , "&#8364;"],
            ["∃" , "&#8707;"],
            ["ƒ" , "&#402;"],
            ["∀" , "&#8704;"],
            ["½" , "&#189;"],
            ["¼" , "&#188;"],
            ["¾" , "&#190;"],
            ["⁄" , "&#8260;"],
            ["Γ" , "&#915;"],
            ["γ" , "&#947;"],
            ["≥" , "&#8805;"],
            [">" , "&#62;"],
            [">" , "&#062;"],
            ["↔" , "&#8596;"],
            ["⇔" , "&#8660;"],
            ["♥" , "&#9829;"],
            ["…" , "&#8230;"],
            ["Í" , "&#205;"],
            ["í" , "&#237;"],
            ["Î" , "&#206;"],
            ["î" , "&#238;"],
            ["¡" , "&#161;"],
            ["Ì" , "&#204;"],
            ["ì" , "&#236;"],
            ["ℑ" , "&#8465;"],
            ["∞" , "&#8734;"],
            ["∫" , "&#8747;"],
            ["Ι" , "&#921;"],
            ["ι" , "&#953;"],
            ["¿" , "&#191;"],
            ["∈" , "&#8712;"],
            ["Ï" , "&#207;"],
            ["ï" , "&#239;"],
            ["Κ" , "&#922;"],
            ["κ" , "&#954;"],
            ["Λ" , "&#923;"],
            ["λ" , "&#955;"],
            ["〈" , "&#9001;"],
            ["«" , "&#171;"],
            ["←" , "&#8592;"],
            ["⇐" , "&#8656;"],
            ["⌈" , "&#8968;"],
            ["“" , "&#8220;"],
            ["≤" , "&#8804;"],
            ["⌊" , "&#8970;"],
            ["∗" , "&#8727;"],
            ["◊" , "&#9674;"],
            ["‹" , "&#8249;"],
            ["‘" , "&#8216;"],
            ["<" , "&#60;"],
            ["<" , "&#060;"],
            ["¯" , "&#175;"],
            ["—" , "&#8212;"],
            ["µ" , "&#181;"],
            ["·" , "&#183;"],
            ["−" , "&#8722;"],
            ["Μ" , "&#924;"],
            ["μ" , "&#956;"],
            ["∇" , "&#8711;"],
            ["" , "&#160;"],
            ["–" , "&#8211;"],
            ["≠" , "&#8800;"],
            ["∋" , "&#8715;"],
            ["¬" , "&#172;"],
            ["∉" , "&#8713;"],
            ["⊄" , "&#8836;"],
            ["Ñ" , "&#209;"],
            ["ñ" , "&#241;"],
            ["Ν" , "&#925;"],
            ["ν" , "&#957;"],
            ["Ó" , "&#211;"],
            ["ó" , "&#243;"],
            ["Ô" , "&#212;"],
            ["ô" , "&#244;"],
            ["Œ" , "&#338;"],
            ["œ" , "&#339;"],
            ["Ò" , "&#210;"],
            ["ò" , "&#242;"],
            ["‾" , "&#8254;"],
            ["Ω" , "&#937;"],
            ["ω" , "&#969;"],
            ["Ο" , "&#927;"],
            ["ο" , "&#959;"],
            ["⊕" , "&#8853;"],
            ["∨" , "&#8744;"],
            ["ª" , "&#170;"],
            ["º" , "&#186;"],
            ["Ø" , "&#216;"],
            ["ø" , "&#248;"],
            ["Õ" , "&#213;"],
            ["õ" , "&#245;"],
            ["⊗" , "&#8855;"],
            ["Ö" , "&#214;"],
            ["ö" , "&#246;"],
            ["¶" , "&#182;"],
            ["∂" , "&#8706;"],
            ["‰" , "&#8240;"],
            ["⊥" , "&#8869;"],
            ["Φ" , "&#934;"],
            ["φ" , "&#966;"],
            ["Π" , "&#928;"],
            ["π" , "&#960;"],
            ["ϖ" , "&#982;"],
            ["±" , "&#177;"],
            ["£" , "&#163;"],
            ["′" , "&#8242;"],
            ["″" , "&#8243;"],
            ["∏" , "&#8719;"],
            ["∝" , "&#8733;"],
            ["Ψ" , "&#936;"],
            ["ψ" , "&#968;"],
            ["\"" , "&#34;"],
            ["\"" , "&#034;"],
            ["√" , "&#8730;"],
            ["〉" , "&#9002;"],
            ["»" , "&#187;"],
            ["→" , "&#8594;"],
            ["⇒" , "&#8658;"],
            ["⌉" , "&#8969;"],
            ["”" , "&#8221;"],
            ["ℜ" , "&#8476;"],
            ["®" , "&#174;"],
            ["⌋" , "&#8971;"],
            ["Ρ" , "&#929;"],
            ["ρ" , "&#961;"],
            ["›" , "&#8250;"],
            ["’" , "&#8217;"],
            ["‚" , "&#8218;"],
            ["Š" , "&#352;"],
            ["š" , "&#353;"],
            ["⋅" , "&#8901;"],
            ["§" , "&#167;"],
            ["Σ" , "&#931;"],
            ["σ" , "&#963;"],
            ["ς" , "&#962;"],
            ["∼" , "&#8764;"],
            ["♠" , "&#9824;"],
            ["⊂" , "&#8834;"],
            ["⊆" , "&#8838;"],
            ["∑" , "&#8721;"],
            ["⊃" , "&#8835;"],
            ["¹" , "&#185;"],
            ["²" , "&#178;"],
            ["³" , "&#179;"],
            ["⊇" , "&#8839;"],
            ["ß" , "&#223;"],
            ["Τ" , "&#932;"],
            ["τ" , "&#964;"],
            ["∴" , "&#8756;"],
            ["Θ" , "&#920;"],
            ["θ" , "&#952;"],
            ["ϑ" , "&#977;"],
            [" " , "&#8201;"],
            ["Þ" , "&#222;"],
            ["þ" , "&#254;"],
            ["˜" , "&#732;"],
            ["×" , "&#215;"],
            ["™" , "&#8482;"],
            ["Ú" , "&#218;"],
            ["ú" , "&#250;"],
            ["↑" , "&#8593;"],
            ["⇑" , "&#8657;"],
            ["Û" , "&#219;"],
            ["û" , "&#251;"],
            ["Ù" , "&#217;"],
            ["ù" , "&#249;"],
            ["¨" , "&#168;"],
            ["ϒ" , "&#978;"],
            ["Υ" , "&#933;"],
            ["υ" , "&#965;"],
            ["Ü" , "&#220;"],
            ["ü" , "&#252;"],
            ["℘" , "&#8472;"],
            ["Ξ" , "&#926;"],
            ["ξ" , "&#958;"],
            ["Ý" , "&#221;"],
            ["ý" , "&#253;"],
            ["¥" , "&#165;"],
            ["ÿ" , "&#255;"],
            ["Ÿ" , "&#376;"],
            ["Ζ" , "&#918;"],
            ["ζ" , "&#950;"]

        ];

        for (var i = 0; i < specialList.length; i++) {
            var replacer = new RegExp(specialList[i][1], "g");
            str = str.replace(replacer, specialList[i][0]);
        }
        return str
    }

    WinJS.Namespace.define("Helper", {
        stripScripts: stripScripts,
        htmlSpecialChars: htmlSpecialChars
    });
})();